package com.hand.wfive.view;

import android.graphics.Bitmap;

import androidx.annotation.NonNull;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.hand.wfive.loginAndVip.UserManager;
import com.hand.wfive.util.ImageUtils;

import java.security.MessageDigest;

public class WatermarkTransformation extends BitmapTransformation {

    private static final String ID = "com.hand.wfive.view.WatermarkTransformation";
    private static final byte[] ID_BYTES = ID.getBytes(CHARSET);

    @Override
    protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
        if (UserManager.getInstance().isVip()) {
            return toTransform;
        }
        return ImageUtils.addWatermark(toTransform);
    }

    @Override
    public boolean equals(Object o) {
        return o instanceof CenterCrop;
    }

    @Override
    public int hashCode() {
        return ID.hashCode();
    }

    @Override
    public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
        messageDigest.update(ID_BYTES);
    }
}
